package com.mz.ozy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.mz.ozy.R;

import java.util.List;

/**
 * Created by Administrator on 2018/11/22.
 */

public class HistroySearchTagAdapter<T> extends BaseAdapter {
    private Context mContext;
    private List<T> mDataList;
    private int selectPosition;

    public HistroySearchTagAdapter(Context context, List<T> mDataList) {
        this.mContext = context;
        this.mDataList = mDataList;

    }

    public List<T> getmDataList() {
        return mDataList;
    }

    public void setmDataList(List<T> mDataList) {
        this.mDataList = mDataList;
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_tag, null);
        TextView tagTv = view.findViewById(R.id.tagTv);
        String t = (String) mDataList.get(position);

//        T t1 = mDataList.get(position);
        tagTv.setText(t);

        return view;
    }

    public int getSelectPosition() {
        return selectPosition;
    }

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
        notifyDataSetChanged();
    }

    /**
     * 刷新数据
     *
     * @param datas
     */
    public void refresh(List<T> datas) {
        this.mDataList.clear();
        this.mDataList.addAll(datas);
        notifyDataSetChanged();
    }

    /**
     * 刷新数据
     *
     * @param data
     */
    public void updata(List<T> data) {
        this.mDataList = data;
        notifyDataSetChanged();
    }

    /**
     * 添加数据
     *
     * @param datas
     */
    public void addData(List<T> datas) {
        this.mDataList.addAll(datas);
        notifyDataSetChanged();
    }

    /**
     * 移除数据
     *
     * @param position
     */
    public void remove(int position) {
        if (position >= 0 && position < mDataList.size()) {
            mDataList.remove(position);
            notifyDataSetChanged();
        }
    }

    public RvItemOnclickListener getRvItemOnclickListener() {
        return mRvItemOnclickListener;
    }

    public void setRvItemOnclickListener(RvItemOnclickListener rvItemOnclickListener) {
        mRvItemOnclickListener = rvItemOnclickListener;
    }

    protected RvItemOnclickListener mRvItemOnclickListener;


    public interface RvItemOnclickListener {

        void RvItemOnclick(int position);
    }
}
